import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaSwitch } from 'comsMobx';
import { WeaSearchGroup, WeaFormItem, WeaRightMenu, WeaLocaleProvider, WeaErrorPage, WeaTools, WeaDialog } from 'ecCom'
import { Button } from 'antd';
const getLabel = WeaLocaleProvider.getLabel;

@observer
class WfSource extends React.Component {

    constructor(props) {
        super(props);

        this.getSearchs;
    }

    render() {
        const { isShow, setDialogShow } = this.props;
        return (
            <div>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@5xrm4i`}
                    onCancel={() => setDialogShow('newflow', false)}
                    visible={isShow}
                    style={{
                        width: "650px",
                        height: "200px"
                    }}
                    hasScroll={true}
                    buttons={this.getButtons()}
                    icon={'icon-coms-workflow'}
                    iconBgcolor='#0079DE'
                    title={getLabel(518517, '流程来源')}
                    moreBtn={this.getMoreBtns()}
                >
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@pg9og7`} {...this.getMoreBtns()}>
                        {
                            <div>  {this.getSearchs()}
                            </div>
                        }
                    </WeaRightMenu>
                </WeaDialog>
            </div>
        );
    }

    //流程中心应用--操作菜单--流程来源Dialog--condition渲染
    getSearchs = () => {
        const { wfMobileSettingStore } = this.props;
        const { newflowForm, newflowFields = [] } = wfMobileSettingStore;
        let group = [];
        let items = [];
        if (newflowForm && newflowForm.isFormInit) {
            const formParams = newflowForm && newflowForm.getFormParams();
            const isAll = formParams && formParams.sourcetype == 0;
            newflowFields.map(field => {
                const domkey = field.domkey[0];
                if (domkey === "sourcetype" || (domkey === "workflowids" && !isAll)) {
                    items.push({
                        com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@lq3ffb@${domkey}`}
                            label={`${field.label}`}
                            labelCol={{ span: `${field.labelcol}` }}
                            wrapperCol={{ span: `${field.fieldcol}` }}
                            error={newflowForm.getError(field)}
                            tipPosition="bottom"
                        >
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@12ca2j@${domkey}`} fieldConfig={field} form={newflowForm} formParams={formParams} />
                        </WeaFormItem>),
                        col: 1
                    });
                }
            });
        }

        group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@8js7k6@group1`} needTigger={false} showGroup={true} items={items} />);
        return group;
    }

    //流程中心应用--操作菜单--流程来源Dialog--更多按钮
    getMoreBtns() {
        let btns = [];
        btns.push({
            key: '0',
            icon: <i className='icon-coms-Preservation' />,
            content: getLabel(86, '保存'),
            onClick: key => this.saveData(),
        });
        return { datas: btns };
    }

    //流程中心应用--操作菜单--流程来源Dialog--底部按钮
    getButtons() {
        let btn = [];
        btn.push(
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@lccny4@save`} type="primary" onClick={this.saveData} >{getLabel(86, '保存')}</Button>)
        )
        return btn;
    }

    //流程中心应用--操作菜单--流程来源Dialog--保存方法
    saveData = () =>  {
        const { wfMobileSettingStore } = this.props;
        const { doSaveMobilecenterConfig } = wfMobileSettingStore;
        doSaveMobilecenterConfig({ type: "newflow" });
    }
}


export default WeaTools.tryCatch(React,
    props => < WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@j1ew0v`} msg={
        props.error ? props.error : '对不起，该页面异常，请联系管理员！'
    }
    />, {
    error: ""
}
)(WfSource);